<?php
//display URL
function fts_show_shorturl($post){
	$postid = $post->ID;
	$shorturl = get_post_meta($postid, 'shorturl', true);
	if (empty($shorturl)){$shorturl = get_post_meta($postid, 'short_url', true);}
	echo $shorturl;
}

//Create URL On Demand 
function fts_shorturl($posturl, $api, $to_return = false){
	$api = strip_tags($api);
	$api = preg_replace("/[^a-zA-Z0-9]/", "", $api);
	
	$options = get_option('fts_urlfx');
	$apiuser_supr = $options['apiuser_supr'];
	$apikey_supr = $options['apikey_supr'];
	$apiuser_bitly = $options['apiuser_bitly'];
	$apikey_bitly = $options['apikey_bitly'];
	$apiuser_trim = $options['apiuser_trim'];
	$apikey_trim = $options['apikey_trim'];
	$apiuser_snip = $options['apiuser_snip'];
	$apikey_snip = $options['apikey_snip'];
	$snipprefix = $options['snipprefix'];
	$apikey_cligs = $options['apikey_cligs'];
	$apiuser_shortie = $options['apiuser_shortie'];
	$apikey_shortie = $options['apikey_shortie'];
	$apikey_pingfm = $options['apikey_pingfm'];
	$apikey_awesm = $options['apikey_awesm'];
		
	$ondemand = new FTShorten();
	$ondemand->url = $posturl;
	$selectedservice = $urlservice;
	switch ($urlservice){
		case 'supr': $ondemand->name = htmlentities($apiuser_supr, ENT_QUOTES); $ondemand->apikey = htmlentities($apikey_supr, ENT_QUOTES); break;
		case 'bitly': $ondemand->name = htmlentities($apiuser_bitly, ENT_QUOTES); $ondemand->apikey = htmlentities($apikey_bitly, ENT_QUOTES); break;
		case 'trim': $ondemand->name = htmlentities($apiuser_trim, ENT_QUOTES); $ondemand->apikey = htmlentities($apikey_trim, ENT_QUOTES); break;
		case 'snipurl': $ondemand->name = htmlentities($apiuser_snip, ENT_QUOTES); $ondemand->apikey = htmlentities($apikey_snip, ENT_QUOTES); $selectedservice = $snipprefix; break;		
		case 'cligs': $ondemand->apikey = htmlentities($apikey_cligs, ENT_QUOTES); break;		
		case 'shortie': $ondemand->name = htmlentities($apiuser_shortie, ENT_QUOTES); $ondemand->apikey = htmlentities($apikey_shortie, ENT_QUOTES); break;		
		case 'pingfm': $ondemand->apikey = htmlentities($apikey_pingfm, ENT_QUOTES); $ondemand->pingfmapi = 'f51e33510d3cbe2ff1e16a4a4897f099'; break;
		case 'awesm': $ondemand->apikey =  htmlentities($apikey_awesm, ENT_QUOTES); break;	
		default: break;
	}
	$ondemand->service = $selectedservice;
	$new_url = $ondemand->shorturl();
	if($to_return){return $new_url;}else{echo $new_url;}
}
?>